package cn.yanglq.Rss.core;


import cn.yanglq.Rss.core.quartz.QuartzManager;
import cn.yanglq.Rss.core.quartz.TestJob;
import cn.yanglq.Rss.core.rssManage.Rss;
import cn.yanglq.Rss.core.rssManage.RssBean;
import cn.yanglq.Rss.core.rssManage.RssUtil;
import cn.yanglq.Rss.core.util.fileUtil.FileOperation;
import cn.yanglq.Rss.core.util.mailUtil.SendMail;

import java.io.IOException;
import java.security.GeneralSecurityException;

public class Main {

    public static void main(String[] args) throws IOException, GeneralSecurityException, ClassNotFoundException {
        String url = "https://www.zhihu.com/rss";
        String filePath = "D://";
        Rss t = new Rss();
        RssBean rs;
        rs = t.getRSSrsult(url);
        String title = rs.getTitle() + ".doc";
//        System.out.println(rs.getTitle());
        String result = RssUtil.rssBuild(rs).toString();
        FileOperation.contentToTxt(filePath + title, result);
        SendMail sm = new SendMail();
//        sm.sendMail(title, null);
//        try {
//            doQuartz();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
    }

    public static void doQuartz() throws InterruptedException {
        TestJob job = new TestJob();
        String jobs = job.getClass().getName();
        String job_name = "sendMail";
        System.out.println("【系统启动】开始(每天下午18点1分开启任务)...");
        QuartzManager.addJob(job_name, jobs, "0 1 18 * * ? *", null);
////QuartzManager.addJob(job_name, job, "0 0/3 8-20 ? ? *");
//
//        Thread.sleep(5000);
//        System.out.println("【修改时间】开始(每2秒输出一次)...");
//        QuartzManager.modifyJobTime(job_name, "10/2 * * * * ?");
//        Thread.sleep(6000);
//        System.out.println("【移除定时】开始...");
//        QuartzManager.removeJob(job_name);
//        System.out.println("【移除定时】成功");
//
//        System.out.println("/n【再次添加定时任务】开始(每10秒输出一次)...");
//        QuartzManager.addJob(job_name, jobs, "*/10 * * * * ?");
//        Thread.sleep(60000);
//        System.out.println("【移除定时】开始...");
//        QuartzManager.removeJob(job_name);
//        System.out.println("【移除定时】成功");
    }
}

